<?php

namespace App\Http\Controllers;

use App\Helpers\ResponseData;
use App\Models\ConfigTable;
use Illuminate\Http\Request;

class ConfigController extends Controller
{
    use ResponseData;
    public function list(ConfigTable $model,Request $request){
        $size = $request->input('size',10);
        if($request->filled('status')&&$request->status=='all'){
            $data = $model->orderBy('id','desc')->get();
        }else{
            $data = $model->orderBy('id','desc')->paginate($size);
        }
        return $this->success($data);
    }
    public function store(ConfigTable $model,Request $request){
        $data = $request->all();
        $model->fill($data);
        $model->save();
        return $this->success('保存成功');
    }
    public function edit(ConfigTable $model,Request $request){
        $data = $model->find($request->id);
        return $this->success($data);
    }
    public function update(ConfigTable $model,Request $request){
        $data = $model->find($request->id);
        $data->update($request->all());
        return $this->success('修改成功');
    }
    public function destory(ConfigTable $model,Request $request){
        $data = $model->find($request->id);
        $data->delete();
    }
}
